package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.*;
import com.hualude.roadsign.service.RoadLineManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xu_jiaHui on 2017/8/15.
 */
@Controller
@RequestMapping("/rds_roadLineController")
public class RoadLineManageController {

    @Resource
    private RoadLineManageService roadLineManageService;

    @RequestMapping("/getRoadLine4DT")
    @ResponseBody
    public DTResponseDto getRoadLine4DT(DTRequestDto dtRequestDto,
                                        String actorIds,
                                        Integer orgId,
                                        Boolean audit,
                                        String startRoad,
                                        String endRoad,
                                        String roadName) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = roadLineManageService.getRoadLine4DT(
                    dtRequestDto, actorIds, orgId, audit, startRoad, endRoad, roadName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/deleteRoadLine")
    @ResponseBody
    public JsonMsgDto deleteRoadLine(String roadLineIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.deleteRoadLine(roadLineIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/updateRoadLine")
    @ResponseBody
    public JsonMsgDto updateRoadLine(RoadLineDto roadLineDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.updateRoadLine(roadLineDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/addRoadLine")
    @ResponseBody
    public JsonMsgDto addRoadLine(RoadLineDto roadLineDto) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.addRoadLine(roadLineDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/auditRoadLine")
    @ResponseBody
    public JsonMsgDto auditRoadLine(String roadLineIds) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.auditRoadLine(roadLineIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCoordinatesById")
    @ResponseBody
    public JsonMsgDto getCoordinatesById(Integer roadLineId, Integer type) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getCoordinatesById(roadLineId, type));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByRoadName")
    @ResponseBody
    public JsonMsgDto getStartRoadByRoadName(String roadName, String actorIds, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineManageService.getStartRoadByRoadName(roadName, actorIds, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping("/getEndRoadByStartRoad")
    @ResponseBody
    public JsonMsgDto getEndRoadByStartRoad(String roadLineRoadName, String startRoad, String actorIds, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineManageService.getEndRoadByStartRoad(roadLineRoadName, startRoad, actorIds, orgId));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }


    @RequestMapping("/getCity4RoadLine")
    @ResponseBody
    public JsonMsgDto getCity4RoadLine(String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getCity4RoadLine(actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByCity")
    @ResponseBody
    public JsonMsgDto getStartRoadByCity(String city, String actorIds, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getStartRoadByCity(city, actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad4App")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getSectionByStartRoad4App(city, roadName, actorIds, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadLine4APP")
    @ResponseBody
    public JsonMsgDto getRoadLine4APP(String actorIds,
                                       Integer orgId,
                                       Integer mCount,
                                       Integer mSize,
                                       String city,
                                       String startRoad,
                                       String endRoad,
                                       String roadName) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getRoadLine4APP(
                    actorIds, orgId, mCount, mSize, city, startRoad, endRoad, roadName));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }
    @RequestMapping("/getRoadLineById")
    @ResponseBody
    public JsonMsgDto getRoadLineById(Integer roadLineId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getRoadLineById(roadLineId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadName4RoadLineByCity")
    @ResponseBody
    public JsonMsgDto getRoadName4RoadLineByCity(String actorIds, Integer orgId, String city, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(roadLineManageService.getRoadName4RoadLineByCity(actorIds, orgId, city, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByRoadName4App")
    @ResponseBody
    public JsonMsgDto getStartRoadByRoadName4App(String city, String roadName, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineManageService.getStartRoadByRoadName4App(city, roadName, actorIds, orgId, mCount, mSize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getEndRoadByStartRoad4App")
    @ResponseBody
    public JsonMsgDto getEndRoadByStartRoad4App(String city, String roadName, String startRoad, String actorIds, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineManageService.getEndRoadByStartRoad4App(city, roadName, startRoad, actorIds, orgId, mCount, mSize));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getRoadLine4Map4App")
    @ResponseBody
    public JsonMsgDto getRoadLine4Map4App(Integer orgId,
                                          String actorIds,
                                          double neLongitude,
                                          double neLatitude,
                                          double swLongitude,
                                          double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(roadLineManageService.getRoadLine4Map4App
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }
}
